<?php
import("ORG.Util.HashMap");
include ("./Public/sImage.class.php");
class BaseAction extends Action{

    var $mid;

    public function _initialize(){
        header("Content-Type:text/html; charset=UTF-8");
        $this->mid = Session::get("mid");
        $this->assign("mid",$this->mid);
        $this->my = Session::get('userInfo');
        $this->assign("my",$this->my);
        $this->fastlink = D ('Article')->where("nid=1")->order('id desc')->top3();
        $this->link1 = D('Link')->where("nid=2")->top10();
        $this->link2 = D('Link')->where("nid=9")->order("orderNum")->top7();


        $this->currentCss =  strtolower(MODULE_NAME._.ACTION_NAME);//引入当前CSS

        $this->nav = D('Sysnav')->where("status<>0")->order('orderNum asc')->findAll();//导航菜单
        $this->nav2 =  D('Sysnav')->where("status<>0")->order('orderNum asc')->findAll();//导航菜单

        //$this->category = D('Category')->where("fid=0 and nid=".$_GET['nid'])->order('id')->findAll();
        //dump($this->category);
        //$this->statNum = D('Sysstat')->count();//访问统计

        //$this->nidInfo = D('Sysnav')->find("id=".$_GET['nid']);
        //dump($this->nidInfo);

        //dump($this->currentRest1);
        $this->affiche = D('Affiche')->order('id desc')->top3();
        //dump($this->affiche);
        //图片新闻
        $this->piclist = D('Picture')->order('id desc')->top2();
        //dump($this->piclist);
        //网站基本信息
        $this->syssite = D('Syssite')->find(1);
        //dump($this->syssite);
        //在线调查
        //$this->survey = D('Survey')->order('id desc')->find();
        //$this->answer= D('Surveyanswer')->findAll("surveyID=".$this->survey['id']);
        //dump($this->answer);

        $this->pic30 =D('Picture')->where("nid=30")->top5();//案例
        $this->pic28 =D('Picture')->where("nid=28")->top5();//功能模块
        $this->a29 =D('Article')->where("nid=29")->top5();//功能模块
        $this->a31 =D('Article')->where("nid=31")->top5();//功能模块

        //我的排名
        if($this->mid){
            $count = D("User")->count("totalVote > ".$this->my["totalVote"]);
            $this->myrank = 1 + intval($count);
        }

        //dump(D("User")->getLastSql());





    }

    function validateLogin(){
        //$this->assign("mid",Session::get("mid"));
        //dump($this->mid);
        if(empty($this->mid)){
            goUrl(__APP__."/public/login");
        }
    }

    function validateLoginFriend(){
        if(empty($this->mid)){
            $this->jumpUrl = __APP__."/index/index";
            $this->error("你还没有登录，请先登录");
        }
    }


    function upload($path){
        import("ORG.Net.UploadFile");
        $upload = new UploadFile();
        $upload->maxSize  = 32922000 ;
        $upload->allowExts  = explode(',','jpg,gif');
        $upload->savePath = "$path";
        //执行上传操作
        $result = $upload->upload();
        if(!$result){
            $this->error("上传出错! ".$upload->getErrorMsg());
        }
        $result = $upload->getUploadFileInfo();

        return $result;
    }

    function Thumb($file,$w,$h){

        $img = new sImage();
        $tmp[] = explode(".", $file);

        $tmp[0][1].="_s";
        $tofile = implode(".", $tmp[0]);
        //        dump($tofile);exit;
        $img->cutThumb($file,$tofile,$w,$h);

        return $tofile;
    }




}
?>